package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teaching.dao.TeachingClassDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingClass;
import com.ruoyi.teaching.service.ITeachingClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/class")
public class TeachingClassController extends BaseController
{
    @Autowired
    private ITeachingClassService teachingClassService;
    @Autowired
    private TeachingClassDao teachingClassDao;

    /**
     * 查询班级信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingClass teachingClass)
    {
        startPage();
        List<TeachingClass> list = teachingClassService.selectTeachingClassList(teachingClass);
        return getDataTable(list);
    }

    /**
     * 导出班级信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:class:export')")
    @Log(title = "班级信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingClass teachingClass)
    {
        List<TeachingClass> list = teachingClassService.selectTeachingClassList(teachingClass);
        ExcelUtil<TeachingClass> util = new ExcelUtil<TeachingClass>(TeachingClass.class);
        util.exportExcel(response, list, "班级信息数据");
    }

    /**
     * 获取班级信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:class:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return AjaxResult.success(teachingClassService.selectTeachingClassByClassId(classId));
    }
    /**
     * 获取班级或办公室信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('teaching:college:query')")
    @GetMapping(value = "code/{code}")
    public AjaxResult getCollegeList(@PathVariable("code") Long code)
    {
        return AjaxResult.success(teachingClassDao.findByCode(code));
    }

    /**
     * 新增班级信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:class:add')")
    @Log(title = "班级信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingClass teachingClass)
    {
        return toAjax(teachingClassService.insertTeachingClass(teachingClass));
    }

    /**
     * 修改班级信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:class:edit')")
    @Log(title = "班级信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingClass teachingClass)
    {
        return toAjax(teachingClassService.updateTeachingClass(teachingClass));
    }

    /**
     * 删除班级信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:class:remove')")
    @Log(title = "班级信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(teachingClassService.deleteTeachingClassByClassIds(classIds));
    }
}
